<template>
  <div class="leaderboard">
    <div class="leaderboard__top">
      <div class="leaderboard__title">
        {{ boardTitle }}
      </div>
      <div class="leaderboard__filter">
        <a-select style="width: 100%" placeholder="选择排序方式" v-on:change="handleChange" v-model="value">
          <a-select-option value="1">按答题次数排序</a-select-option>
          <a-select-option value="2">按正确率排序</a-select-option>
          <a-select-option value="3">按获得积分排序</a-select-option>
        </a-select>
      </div>
    </div>
    <div class="leaderboard__table">
      <a-table :columns="columns" :dataSource="data" />
    </div>
  </div>
</template>

<script>
import { defineComponent, ref } from 'vue'
import { Table } from 'ant-design-vue'

export default defineComponent({
  name: 'Leaderboard',
  components: {},
  props: {
    leaderboardData: {
      type: Array,
      default: () => []
    },
    boardTitle: {
      type: String,
      default: '积分排行榜'
    },
    class_id: { // 添加 class_id 的 prop
      type: Number,
      required: true
    }
  },
  setup(props) {
    console.log("传递的 class_id:", props.class_id);
    const columns = [
      {
        title: '姓名',
        dataIndex: 'name',
        key: 'name'
      },
      {
        title: '排名',
        dataIndex: 'id',
        key: 'id'
      },
      {
        title: '答题次数',
        dataIndex: 'attempts',
        key: 'attempts'
        // sorter: (a, b) => a.attempts - b.attempts,
        // sortDirections: ['descend', 'ascend']
      },
      {
        title: '正确率',
        dataIndex: 'accuracy',
        key: 'accuracy',
        // sorter: (a, b) => a.accuracy - b.accuracy,
        // sortDirections: ['descend', 'ascend'],
        render: text => `${text}%`
      },
      {
        title: '获得积分',
        dataIndex: 'points',
        key: 'points'
      }
    ]

    const data = ref([
      {
        id: 23,
        name: '刘晓晓',
        attempts: 194,
        accuracy: 82,
        points: 896
      },
      {
        id: 68,
        name: '李四',
        attempts: 40,
        accuracy: 75,
        points: 1800
      },
      {
        id: 3,
        name: '王五',
        attempts: 60,
        accuracy: 90,
        points: 2500
      },
      {
        id: 4,
        name: '赵六',
        attempts: 30,
        accuracy: 70,
        points: 1500
      },
      {
        id: 5,
        name: '孙七',
        attempts: 55,
        accuracy: 85,
        points: 2200
      }
    ])

    const finalData = ref(data.value)
    const handleChange = value => {
      switch (value) {
        case '1':
          finalData.value = data.value.sort((a, b) => a.attempts - b.attempts)
          break
        case '2':
          finalData.value = data.value.sort((a, b) => a.accuracy - b.accuracy)
          break
        case '3':
          finalData.value = data.value.sort((a, b) => a.points - b.points)
          break
        default:
          finalData.value = data.value
      }
    }
    function apiget(){
      
    }


    return {
      columns,
      data,
      value: '1',
      handleChange
    }
  }
})
</script>

<style scoped lang="less">
.leaderboard {
  width: 100%;
  padding: 20px;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(253, 226, 151, 1) 0%, rgba(254, 246, 224, 1) 16.33%, rgba(255, 255, 255, 1) 23.41%, rgba(255, 255, 255, 1) 100%);
  border-radius: 10px;
  overflow: auto;

  vertical-align: top;

  .leaderboard__top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 64px;
    .leaderboard__title {
      font-size: 30px;
      font-weight: 400;
      letter-spacing: 0px;
      line-height: 43.44px;
      color: rgba(51, 51, 51, 1);
      text-align: left;
      vertical-align: top;
    }

    .leaderboard__filter {
      width: 200px;
      height: 100%;
      // background: linear-gradient(180deg, rgba(213, 226, 253, 1) 0%, rgba(233, 243, 245, 1) 100%);
      // box-shadow: 0px 0px 8px rgba(162, 136, 72, 0.4);
    }
  }
  /deep/ .ant-table-tbody {
    font-size: 26px;
    font-weight: 400;
    letter-spacing: 0px;
    line-height: 30.47px;
    color: rgba(51, 51, 51, 1);
    text-align: left;
  }
  /deep/ .ant-table-tbody > tr > td {
    padding-top: 20px;
    border-top: 12px solid #fff !important;
    border-bottom: 12px solid #fff !important;
    background-color: rgba(250, 250, 250, 1);
  }

  /deep/ .ant-table-cell::before {
    height: 0px !important;
  }
}
</style>
